using System.Collections.Generic;
using Framework.Core;

public class WorldContext
{
    public MapGrid MapGrid { get; private set; }
    public Player Player;
    public ActorBase ActiveActor;
    private Queue<NpcOptCmdBase> _cmds;
    public WorldContext()
    {
        MapGrid = new MapGrid();
        _cmds = new Queue<NpcOptCmdBase>();
    }
    public void ExecuteInteractive(Npc npc, ActorBase target)
    {
        if (target == null) return;
        if (target.Removed || target.Removing) return;
        var type = target.GetActorType();
        NpcOptCmdBase cmd = null;
        if (type == ActorType.Res)
        {
            cmd = ReferencePool.Get<NpcOptRes>();
        }
        else if (type == ActorType.Door)
        {
            cmd = ReferencePool.Get<PlayerOptDoor>();
        }
        else if (type == ActorType.Tree)
        {
            cmd = ReferencePool.Get<NpcOptTree>();
        }
        if (cmd == null) return;
        cmd.Set(npc, target);
        _cmds.Enqueue(cmd);
    }
    public void Update(float deltaTime)
    {
        var len = _cmds.Count;
        while (len-- > 0)
        {
            var cmd = _cmds.Dequeue();
            cmd.Execute();
            ReferencePool.Release(cmd);
        }
    }
}
